package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author：XueShiHao
 * @Date：2025/6/6 星期五 10:25:07
 * @Email:747278007@qq.com
 * @Description:
 **/
@Slf4j
@Api("对菜品的操作")
@RestController
@RequestMapping("/admin/dish")
public class DishController {
    @Autowired
    private DishService dishService;

    @ApiOperation("对菜品的修改")
    @PutMapping
    public Result update (@RequestBody DishDTO dishDTO){
        log.info("对菜品的修改:{}",dishDTO);
        dishService.updateWithFlavor(dishDTO);
        return Result.success();
    }
    @ApiOperation("根据id查询菜品")
    @GetMapping
    public Result<DishVO> dd(@PathVariable Long id){
        DishVO dishVO=new DishVO();
        dishVO.setId(id);
        dishService.getByIdWithFlavor(id);
       return Result.success(dishVO);
    }
    @ApiOperation("新增菜品")
    @PostMapping
    public Result oo(@RequestBody DishDTO dishDTO){
        dishService.saveWithFlavor(dishDTO);
        log.info("菜品新增成功：{}",dishDTO);
        return Result.success();
    }
    @ApiOperation("根据分类id查询菜品")
    @GetMapping("/list")
    public Result<DishVO> ii(@PathVariable Long categoryId){
        DishVO dishVO=new DishVO();
        dishVO.setCategoryId(categoryId);
        dishService.list(categoryId);
        return Result.success(dishVO);
    }
    @ApiOperation("菜品的分页查询")
    @GetMapping("/page")
    public Result<PageResult> dd(DishPageQueryDTO dishPageQueryDTO){
        PageResult pageResult=dishService.pageQuery(dishPageQueryDTO);
        log.info("菜品的分页查询:{}",dishPageQueryDTO);
        return Result.success(pageResult);
    }
    @ApiOperation("菜品的起售以及停售")
    @PostMapping("/status/{status")
    public Result<String> opp(@PathVariable Integer status,Long id){
        dishService.startOrStop(status, id);
        return Result.success();

    }
    /**






    */
}
